<template>
	<view class="container">
		<view class="mine">
			<view class="mineInfo" @click="my">
				<view class="avatar">
					<image v-if="info.user_avatar" :src="info.user_avatar" mode="aspectFill"></image>
					<image v-else src="@/static/img/avatar.png" mode="aspectFill"></image>
				</view>
				<view class="name">
					<view class="nickName">{{ info.nick_name ? info.nick_name : info.user_name }}</view>
					<view class="userName">账号：{{ info.user_name }}</view>
				</view>
			</view>
			<view class="mineSet" @click="my">
				<uni-icons type="gear" size="22" color="#fff"></uni-icons>
			</view>
		</view>
		<uni-list>
			<uni-list-item link title="消息" :show-extra-icon="true" :extra-icon="icon.msg" :show-badge="msgNum > 0" :badge-text="msgNum" to="/pages/mine/msg/msg"></uni-list-item>
			<uni-list-item link title="公告" :show-extra-icon="true" :extra-icon="icon.notice" to="/pages/mine/notice/notice"></uni-list-item>
		</uni-list>
		<uni-list>
			<uni-list-item v-if="rules.includes('948')" link title="员工" :show-extra-icon="true" :extra-icon="icon.person" to="/pages/mine/staff/staff"></uni-list-item>
			<uni-list-item v-if="rules.includes('1029')" link title="分组" :show-extra-icon="true" :extra-icon="icon.staff" to="/pages/mine/group/group"></uni-list-item>
			<uni-list-item v-if="rules.includes('949')" link title="岗位" :show-extra-icon="true" :extra-icon="icon.auth" to="/pages/mine/auth/auth"></uni-list-item>
		</uni-list>
		<uni-list>
			<uni-list-item link title="关于我们" :show-extra-icon="true" :extra-icon="icon.info"></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
import api from '@/api/api';
export default {
	data() {
		return {
			rules: [],
			info: {},
			msgNum: 0,
			icon: {
				msg: { color: '#2979ff', size: '20', type: 'chat' },
				notice: { color: '#2979ff', size: '20', type: 'notification' },
				person: { color: '#2979ff', size: '20', type: 'person' },
				staff: { color: '#2979ff', size: '20', type: 'staff' },
				auth: { color: '#2979ff', size: '20', type: 'auth' },
				info: { color: '#2979ff', size: '20', type: 'info' }
			}
		};
	},
	onLoad() {
		this.rules = uni.getStorageSync('rules');
	},
	onShow() {
		this.getUserInfo();
		this.getMsgNum();
	},
	methods: {
		getUserInfo() {
			api.getUserInfo({}).then((data) => {
				this.info = data.data.profile;
			});
		},
		getMsgNum() {
			api.msgList({ is_view: 0 }).then((data) => {
				this.msgNum = data.data.total;
			});
		},
		my(){
			uni.navigateTo({
				url:'/pages/mine/my/my'
			})
		}
	}
};
</script>

<style lang="scss">
.container {
	padding: 20rpx;
	.mine {
		padding: 60rpx 30rpx;
		background: linear-gradient(to right, #5287f9, #4399fc);
		border-radius: 20rpx;
		border-top-right-radius: 60rpx;
		box-shadow: $uni-shadow-sm;
		margin-bottom: 20rpx;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.mineInfo {
			display: flex;
			align-items: center;
			.avatar {
				width: 80rpx;
				height: 80rpx;
				margin-right: 20rpx;
				border-radius: 100%;
				overflow: hidden;
				image {
					width: 80rpx;
					height: 80rpx;
				}
			}
			.nickName {
				font-size: 30rpx;
				margin-bottom: 10rpx;
			}
			.userName {
				font-size: 24rpx;
			}
		}
	}
	.uni-list {
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
		box-shadow: $uni-shadow-sm;
	}
}
</style>
